//
//  TFBaseRequest.m
//  TFBase
//
//  Created by Liyadong on 2019/6/25.
//  Copyright © 2019 Liyadong. All rights reserved.
//

#import "TFBaseRequest.h"
#import "HttpRequest.h"

@implementation TFBaseRequest

//******************************************** 一下为基础工具方法 ***************************************


#pragma mark -- basePost
+(void)basePostRequestUrl:(NSString *)url requestParam:(NSDictionary *)param success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    
    DLog(@"POSTFORM接口 = %@， %@", url, param);
    
    [[HttpRequest sharedInstance] postTFFormWithURLString:url parameters:param success:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

+(void)basePostJsonRequestUrl:(NSString *)url requestParam:(NSDictionary *)param success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    
    
    
    DLog(@"POSTJSON接口 = %@， %@", url, param);
    
    [[HttpRequest sharedInstance] postWithURLString:url parameters:param success:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
         
        if (failure) {
            failure(error);
        }
    }];
    
}

#pragma mark -- baseGet
+(void)baseGetRequestUrl:(NSString *)url requestParam:(NSDictionary *)param success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    
    DLog(@"GET接口 = %@， %@", url, param);
    
    [[HttpRequest sharedInstance] getWithURLString:url parameters:param success:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
    }];
}

+(void)baseUpLoadImageWithUrl:(NSString *)url requestParam:(NSDictionary *)param image:(UIImage *)image success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
   
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    DLog(@"上传图片 = %@， %@, %@", url, param, image);
    
    [[HttpRequest sharedInstance] uploadDataWithImage:image URLString:url parameters:param success:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSError *error) {

        if (failure) {
            failure(error);
        }
    }];
}


+(void)feedBackUpLoadImageWithUrl:(NSString *)url requestParam:(NSDictionary *)param images:(NSMutableArray *)images success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
   
    
    [[HttpRequest sharedInstance] uploadFeedDataWithImages:images URLString:url parameters:param success:^(id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
         if (failure) {
            failure(error);
        }
    }];
    
}

@end
